<!DOCTYPE html>
<html>
<head>
	<title>Test Flask API</title>
</head>
<body>
	<h1>Test Flask API</h1>
	<p>Enter IP address and alias:</p>
	<form>
		<label for="ip">IP address:</label>
		<input type="text" id="ip" name="ip"><br><br>
		<label for="alias">Alias:</label>
		<input type="text" id="alias" name="alias"><br><br>
		<input type="button" value="Submit" onclick="sendData_gps()">
	</form>

	<p id="response"></p>

	<script>
		function sendData() {
			// 获取输入的数据
			
			var ip = document.getElementById("ip").value;
			var alias = document.getElementById("alias").value;

			// 发送 AJAX 请求
			var xhr = new XMLHttpRequest();
			var url = "http://127.0.0.1:5000/api/data";
			xhr.open("POST", url, true);
			xhr.setRequestHeader("Content-Type", "application/json");
			xhr.onreadystatechange = function () {
				if (xhr.readyState === 4 && xhr.status === 200) {
					// 处理响应数据
					var response = JSON.parse(xhr.responseText);
					document.getElementById("response").innerHTML = "IP address: " + response.ip +
						", Alias: " + response.alias;
				}
			};
			var data = JSON.stringify({"ip": ip, "alias": alias});
			xhr.send(data);
		}

		function sendData_gps() {
			// 获取输入的数据
			console.log("sss")
			// var ip = document.getElementById("ip").value;
			// var alias = document.getElementById("alias").value;
			ip = "123"
			alias = "345456"
			// 发送 AJAX 请求
			var xhr = new XMLHttpRequest();
			var url = "http://127.0.0.1:5000/api/gps";
			xhr.open("POST", url, true);
			xhr.setRequestHeader("Content-Type", "application/json");
			xhr.onreadystatechange = function () {
				if (xhr.readyState === 4 && xhr.status === 200) {
					// 处理响应数据
					var response = JSON.parse(xhr.responseText);
					document.getElementById("response").innerHTML = "IP address: " + response.ip +
						", Alias: " + response.alias;
				}
			};
			var data = JSON.stringify({"latitude": ip, "longitude": alias});
			xhr.send(data);
		}
	</script>
</body>
</html>